package com.dyit.dao;

import com.dyit.entity.Book;
import com.dyit.vo.BookVo;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface IBookDao extends JpaRepository<Book,Integer> {//在book表里找
//    Book findById(int id);//根据书的id找出书对象
////    List<Integer> findByLibrary(int library);//根据图书馆id找出书的id
    List<Book> findAllByLibrary(int library);
    //根据图书馆id找出所有书

    Book findBookById(int id);
    //根据书的id找书对象

    Book findBookByTitle(String title);
    //根据书的名字找书对象


    int countAllByCategory(String category);
    /**
     * 根据不同类别进行查询该类别对应的数量
     */

    @Query(value = "SELECT DISTINCT book_category FROM book_tab",nativeQuery = true)
    List<String> findAllCategory();
    /**
     * 找到所有类别，放进list里
     */

//    @Query(value = "select book_category,COUNT(book_category) from book_tab GROUP BY book_category",nativeQuery = true)
//    List<Book> countBookByCategory();
}
